﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Reflection;

namespace QL_Truong_Hoc
{
    public partial class frmChonMonNghe : DevExpress.XtraEditors.XtraForm
    {
        public bool Selected { get; set; }
        public int MonID { get; set; }
        public string MonTen { get; set; }

        private int mintKdtID;

        public frmChonMonNghe(int intKdtID = clsConst.gcintNoneValue)
        {
            InitializeComponent();

            mintKdtID = intKdtID;
        }

        private void frmChonKhungDaoTao_Load(object sender, EventArgs e)
        {
            if (mintKdtID > clsConst.gcintNoneValue)
            {
                this.mKhungDaoTaoMonBindingSource.Filter = string.Format("KDT_ID = {0}", mintKdtID);
            }

            // TODO: This line of code loads data into the 'qLTHDataSet.mMon' table. You can move, or remove it, as needed.
            this.mMonTableAdapter.Fill(this.qLTHDataSet.mMon);
            // TODO: This line of code loads data into the 'qLTHDataSet.mKhungDaoTaoMon' table. You can move, or remove it, as needed.
            this.mKhungDaoTaoMonTableAdapter.Fill(this.qLTHDataSet.mKhungDaoTaoMon);
            
            this.Selected = false;
        }

        private void btnChoose_Click(object sender, EventArgs e)
        {
            try
            {
                //lấy dữ liệu
                this.MonID = clsCommon.fncCnvNullToInt(dgvKhung.GetFocusedRowCellValue(colMO_ID));
                this.MonTen = clsCommon.fncCnvNullToString(dgvKhung.GetFocusedRowCellDisplayText(colMO_ID));

                if (this.MonID <= 0)
                {
                    clsCommon.fncMsgInfo("Hãy chọn một môn học.");
                    dgvKhung.Focus();
                    return;
                }
                
                this.Selected = true;

                this.Close();
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            try
            {               
                this.Close();
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
        }
    }
}